package com.hk.service.impl;

import com.hk.mapper.IAdminMapper;
import com.hk.model.Admin;
import com.hk.service.IAdminService;
import com.hk.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/5 18:24
 * @Statement: 管理员账户业务逻辑层
 */
@Service
public class AdminServiceImpl implements IAdminService {

    @Autowired
    IAdminMapper iAdminMapper;

    @Override
    public Admin findByEmailAndPassword(Admin admin) {
        Admin admin1 = iAdminMapper.findByEmailAndPassword(admin);
        return admin1;
    }

    @Override
    public int findByEmail(String email) {
        Admin admin = iAdminMapper.findByEmail(email);
        if (!admin.equals(null)) {
            System.out.println("邮箱已存在，请更换邮箱！");
            return 1;
        }
        return 0;
    }

    @Override
    public List<Admin> findAll(Integer page, Integer limit, Admin t) {
        return null;
    }

    @Override
    public int count(Integer page, Integer limit, Admin t) {
        return 0;
    }

    @Override
    public Admin findById(Integer id) {
        Admin admin = iAdminMapper.findById(id);
        return admin;
    }

    @Override
    public int save(Admin admin) {
        return 0;
    }

    @Override
    public int update(Admin admin) {
        //        修改日期时间
        String dateTimeString = DateUtils.dateTimeString(new Date());
        admin.setGmtModified(dateTimeString);
        int update = iAdminMapper.update(admin);
        if (update == 1) {
            System.out.println("当前管理员信息修改成功");
        }
        return update;
    }

    @Override
    public int updatePassWord(Admin admin) {
        //        修改日期时间
        String dateTimeString = DateUtils.dateTimeString(new Date());
        admin.setGmtModified(dateTimeString);
        int updatePassWord = iAdminMapper.updatePassWord(admin);
        if (updatePassWord == 1) {
            System.out.println("当前管理员密码修改成功");
        }
        return updatePassWord;
    }

    @Override
    public int delete(Integer id) {
        return 0;
    }
}
